<template>
  <div class="container">
    <!-- 点击审核出现的对话框 -->
    <el-dialog title="题目审核" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <!-- 表单区域开始 -->
      <el-form ref="formChkState" :model="formChkState">
        <el-form-item>
          <el-radio-group v-model="formChkState.chkState">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-input type="textarea" v-model="formChkState.chkRemarks" placeholder="请输入审核意见"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hCancel">取 消</el-button>
        <el-button type="primary" @click="hSure">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// 导入审核意见接口
import { choiceCheck } from '@/api/hmmm/questions.js'
export default {
  name: 'QuestionDislog',
  props: ['value', 'sonID'],
  data() {
    return {
      dialogVisible: this.value, // 点击审核控制对话框是否弹出
      // 审核弹框的表单数据
      formChkState: {
        chkState: 1, // 通过/拒绝
        chkRemarks: '' // 审核通过意见
      }
      // getData: []
    }
  },
  watch: {
    value: function (newVal) {
      this.formChkState.chkState = 1
      this.formChkState.ChkStatePass = ''
      this.dialogVisible = newVal
    }
  },
  methods: {
    // 点击确定
    async hSure() {
      this.dialogVisible = false
      this.$emit('input', this.dialogVisible)
      if (this.formChkState.chkRemarks === '') {
        this.$message.warning('请输入审核意见')
        return false
      } else {
        // 调用接口获取审核数据
        const data = {
          id: this.sonID,
          ...this.formChkState
        }
        console.log(data)
        // console.log(this.sonID)
        const res = await choiceCheck(data)
        console.log('审核数据', res)
        this.getData = res
        this.$message.success('操作成功')
        this.$emit('getData')
        // 清空输入框
        this.formChkState.chkRemarks = ''
      }
    },
    // 点击取消
    hCancel() {
      this.dialogVisible = false
      this.$emit('input', this.dialogVisible)
      // 清空输入框
      this.formChkState.chkRemarks = ''
    },
    // 点击关闭按钮
    handleClose(done) {
      this.dialogVisible = false
      this.$emit('input', this.dialogVisible)
      // 清空输入框
      this.formChkState.chkRemarks = ''
    }
  }
}
</script>

<style scoped lang='less'></style>
